<template>
    <div class="index">
<!--        <h1>123456</h1>-->
        <H3 style="margin-left: 20px;margin-top: 20px;">
            {{ getTimeState() }}
        </H3>
        <admin-index v-if="'admin' === maxRole"></admin-index>
        <teacher-index v-if="'teacher' === maxRole" :user-id="userId"></teacher-index>
        <agent-index v-if="'agent' === maxRole" :user-id="userId"></agent-index>
        <channel-index v-if="'channelBusiness' === maxRole" :user-id="userId"></channel-index>
        <!--        <agent-index  :user-id="userId"></agent-index>-->
        <!--        <teacher-index  :user-id="userId"></teacher-index>-->
        <!--        <channel-index  :user-id="userId"></channel-index>-->
    </div>
</template>

<script>
import {VuePage} from "@/layout/mixin/iVue";
import {mapState} from "vuex";
import {getUserCount, getUserLine} from "@/api/user";
import adminIndex from "@/views/models/admin"
import teacherIndex from "@/views/models/teacher"
import agentIndex from "@/views/models/agent"
import channelIndex from "@/views/models/channel"

export default {
    name: "Index",
    mixins: [VuePage],
    components: {adminIndex,teacherIndex,agentIndex,channelIndex},
    data() {
        return {
            roleName:"",
            userId : null,
            maxRole: "",

        }
    },
    computed: {
        ...mapState({
            userInfo: state => state.currentUser,
            userRole: state => state.user,
        })
    },
    created() {
        this.getCurrentUserMaxRole();
    },
    mounted() {
    },
    methods: {
        getCurrentUserMaxRole() {
            this.userId = this.userInfo.id;
            // this.userId = "1462705118964088832";
            if ((this.userInfo.userTypes.includes("admin")) || this.userRole.roles.includes("maxAdmin")) {
                this.roleName=" 管理员";
                this.maxRole = "admin";
            } else if (this.userInfo.userTypes.includes("teacher")) {
                this.roleName=" 老师";
                this.maxRole = "teacher";
            } else if (this.userInfo.userTypes.includes("agent")) {
                this.roleName=" 代理商";
                this.maxRole = "agent";
            } else if (this.userInfo.userTypes.includes("channelBusiness")) {
                this.roleName=" 渠道商";
                this.maxRole = "channelBusiness";
            }
        },
        getTimeState() {
            // 获取当前时间
            let timeNow = new Date();
            // 获取当前小时
            let hours = timeNow.getHours();
            // 设置默认文字
            let state = "";
            // 判断当前时间段
            if (hours >= 0 && hours <= 10) {
                state = "早上好! ";
            } else if (hours > 10 && hours <= 14) {
                state = "中午好! ";
            } else if (hours > 14 && hours <= 18) {
                state = "下午好!";
            } else if (hours > 18 && hours <= 24) {
                state = "晚上好! ";
            }
            return state + this.userInfo.name ;

        }
    }
};
</script>
<style lang="scss" scoped>
.index {
    background-color: #fff;
}

</style>
